package com.bumptech.glide.load.resource.bitmap;

import android.annotation.TargetApi;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.os.Build.VERSION;
import android.util.Log;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.util.MarkEnforcingInputStream;
import com.bumptech.glide.util.Util;
import java.io.IOException;
import java.io.InputStream;
import java.util.EnumSet;
import java.util.Queue;
import java.util.Set;

public abstract class Downsampler
  implements BitmapDecoder<InputStream>
{
  public static final Downsampler AT_LEAST = new Downsampler()
  {
    public String getId()
    {
      return "AT_LEAST.com.bumptech.glide.load.data.bitmap";
    }

    protected int getSampleSize(int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3, int paramAnonymousInt4)
    {
      return Math.min(paramAnonymousInt2 / paramAnonymousInt4, paramAnonymousInt1 / paramAnonymousInt3);
    }
  };
  public static final Downsampler AT_MOST = new Downsampler()
  {
    public String getId()
    {
      return "AT_MOST.com.bumptech.glide.load.data.bitmap";
    }

    protected int getSampleSize(int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3, int paramAnonymousInt4)
    {
      int i = 1;
      int j = (int)Math.ceil(Math.max(paramAnonymousInt2 / paramAnonymousInt4, paramAnonymousInt1 / paramAnonymousInt3));
      int k = Math.max(i, Integer.highestOneBit(j));
      if (k < j);
      while (true)
      {
        return k << i;
        i = 0;
      }
    }
  };
  private static final int MARK_POSITION = 5242880;
  public static final Downsampler NONE = new Downsampler()
  {
    public String getId()
    {
      return "NONE.com.bumptech.glide.load.data.bitmap";
    }

    protected int getSampleSize(int paramAnonymousInt1, int paramAnonymousInt2, int paramAnonymousInt3, int paramAnonymousInt4)
    {
      return 0;
    }
  };
  private static final Queue<BitmapFactory.Options> OPTIONS_QUEUE;
  private static final String TAG = "Downsampler";
  private static final Set<ImageHeaderParser.ImageType> TYPES_THAT_USE_POOL = EnumSet.of(ImageHeaderParser.ImageType.JPEG, ImageHeaderParser.ImageType.PNG_A, ImageHeaderParser.ImageType.PNG);

  static
  {
    OPTIONS_QUEUE = Util.createQueue(0);
  }

  private static Bitmap decodeStream(MarkEnforcingInputStream paramMarkEnforcingInputStream, RecyclableBufferedInputStream paramRecyclableBufferedInputStream, BitmapFactory.Options paramOptions)
  {
    if (paramOptions.inJustDecodeBounds)
      paramMarkEnforcingInputStream.mark(5242880);
    Bitmap localBitmap;
    while (true)
    {
      localBitmap = BitmapFactory.decodeStream(paramMarkEnforcingInputStream, null, paramOptions);
      try
      {
        if (paramOptions.inJustDecodeBounds)
          paramMarkEnforcingInputStream.reset();
        return localBitmap;
        paramRecyclableBufferedInputStream.fixMarkLimit();
      }
      catch (IOException localIOException)
      {
        while (!Log.isLoggable("Downsampler", 6));
        Log.e("Downsampler", "Exception loading inDecodeBounds=" + paramOptions.inJustDecodeBounds + " sample=" + paramOptions.inSampleSize, localIOException);
      }
    }
    return localBitmap;
  }

  private Bitmap downsampleWithSize(MarkEnforcingInputStream paramMarkEnforcingInputStream, RecyclableBufferedInputStream paramRecyclableBufferedInputStream, BitmapFactory.Options paramOptions, BitmapPool paramBitmapPool, int paramInt1, int paramInt2, int paramInt3, DecodeFormat paramDecodeFormat)
  {
    Bitmap.Config localConfig = getConfig(paramMarkEnforcingInputStream, paramDecodeFormat);
    paramOptions.inSampleSize = paramInt3;
    paramOptions.inPreferredConfig = localConfig;
    if (((paramOptions.inSampleSize == 1) || (19 <= Build.VERSION.SDK_INT)) && (shouldUsePool(paramMarkEnforcingInputStream)))
      setInBitmap(paramOptions, paramBitmapPool.getDirty((int)Math.ceil(paramInt1 / paramInt3), (int)Math.ceil(paramInt2 / paramInt3), localConfig));
    return decodeStream(paramMarkEnforcingInputStream, paramRecyclableBufferedInputStream, paramOptions);
  }

  private static Bitmap.Config getConfig(InputStream paramInputStream, DecodeFormat paramDecodeFormat)
  {
    if ((paramDecodeFormat == DecodeFormat.ALWAYS_ARGB_8888) || (paramDecodeFormat == DecodeFormat.PREFER_ARGB_8888) || (Build.VERSION.SDK_INT == 16))
      return Bitmap.Config.ARGB_8888;
    paramInputStream.mark(1024);
    try
    {
      boolean bool3 = new ImageHeaderParser(paramInputStream).hasAlpha();
      bool2 = bool3;
      try
      {
        paramInputStream.reset();
        if (bool2)
          return Bitmap.Config.ARGB_8888;
      }
      catch (IOException localIOException4)
      {
        while (true)
          if (Log.isLoggable("Downsampler", 5))
            Log.w("Downsampler", "Cannot reset the input stream", localIOException4);
      }
    }
    catch (IOException localIOException2)
    {
      while (true)
      {
        boolean bool2;
        if (Log.isLoggable("Downsampler", 5))
          Log.w("Downsampler", "Cannot determine whether the image has alpha or not from header for format " + paramDecodeFormat, localIOException2);
        boolean bool1;
        try
        {
          paramInputStream.reset();
          bool2 = false;
        }
        catch (IOException localIOException3)
        {
          bool1 = Log.isLoggable("Downsampler", 5);
          bool2 = false;
        }
        if (bool1)
        {
          Log.w("Downsampler", "Cannot reset the input stream", localIOException3);
          bool2 = false;
        }
      }
    }
    finally
    {
      try
      {
        paramInputStream.reset();
        throw localObject;
      }
      catch (IOException localIOException1)
      {
        while (true)
          if (Log.isLoggable("Downsampler", 5))
            Log.w("Downsampler", "Cannot reset the input stream", localIOException1);
      }
    }
    return Bitmap.Config.RGB_565;
  }

  @TargetApi(11)
  private static BitmapFactory.Options getDefaultOptions()
  {
    try
    {
      synchronized (OPTIONS_QUEUE)
      {
        BitmapFactory.Options localOptions = (BitmapFactory.Options)OPTIONS_QUEUE.poll();
        if (localOptions == null)
        {
          localOptions = new BitmapFactory.Options();
          resetOptions(localOptions);
        }
        return localOptions;
      }
    }
    finally
    {
    }
  }

  private int getRoundedSampleSize(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5)
  {
    int i;
    int j;
    label20: int k;
    if (paramInt5 == -2147483648)
    {
      i = paramInt3;
      if (paramInt4 != -2147483648)
        break label67;
      j = paramInt2;
      if ((paramInt1 != 90) && (paramInt1 != 270))
        break label74;
      k = getSampleSize(paramInt3, paramInt2, j, i);
      label45: if (k != 0)
        break label89;
    }
    label67: label74: label89: for (int m = 0; ; m = Integer.highestOneBit(k))
    {
      return Math.max(1, m);
      i = paramInt5;
      break;
      j = paramInt4;
      break label20;
      k = getSampleSize(paramInt2, paramInt3, j, i);
      break label45;
    }
  }

  private static void releaseOptions(BitmapFactory.Options paramOptions)
  {
    resetOptions(paramOptions);
    synchronized (OPTIONS_QUEUE)
    {
      OPTIONS_QUEUE.offer(paramOptions);
      return;
    }
  }

  @TargetApi(11)
  private static void resetOptions(BitmapFactory.Options paramOptions)
  {
    paramOptions.inTempStorage = null;
    paramOptions.inDither = false;
    paramOptions.inScaled = false;
    paramOptions.inSampleSize = 1;
    paramOptions.inPreferredConfig = null;
    paramOptions.inJustDecodeBounds = false;
    paramOptions.outWidth = 0;
    paramOptions.outHeight = 0;
    paramOptions.outMimeType = null;
    if (11 <= Build.VERSION.SDK_INT)
    {
      paramOptions.inBitmap = null;
      paramOptions.inMutable = true;
    }
  }

  @TargetApi(11)
  private static void setInBitmap(BitmapFactory.Options paramOptions, Bitmap paramBitmap)
  {
    if (11 <= Build.VERSION.SDK_INT)
      paramOptions.inBitmap = paramBitmap;
  }

  private static boolean shouldUsePool(InputStream paramInputStream)
  {
    boolean bool2;
    if (19 <= Build.VERSION.SDK_INT)
      bool2 = true;
    while (true)
    {
      return bool2;
      paramInputStream.mark(1024);
      try
      {
        ImageHeaderParser.ImageType localImageType = new ImageHeaderParser(paramInputStream).getType();
        boolean bool1 = TYPES_THAT_USE_POOL.contains(localImageType);
        bool2 = bool1;
        try
        {
          paramInputStream.reset();
          return bool2;
        }
        catch (IOException localIOException4)
        {
        }
        if (Log.isLoggable("Downsampler", 5))
        {
          Log.w("Downsampler", "Cannot reset the input stream", localIOException4);
          return bool2;
        }
      }
      catch (IOException localIOException2)
      {
        localIOException2 = localIOException2;
        if (Log.isLoggable("Downsampler", 5))
          Log.w("Downsampler", "Cannot determine the image type from header", localIOException2);
        try
        {
          paramInputStream.reset();
          return false;
        }
        catch (IOException localIOException3)
        {
          while (true)
            if (Log.isLoggable("Downsampler", 5))
              Log.w("Downsampler", "Cannot reset the input stream", localIOException3);
        }
      }
      finally
      {
      }
    }
    try
    {
      paramInputStream.reset();
      throw localObject;
    }
    catch (IOException localIOException1)
    {
      while (true)
        if (Log.isLoggable("Downsampler", 5))
          Log.w("Downsampler", "Cannot reset the input stream", localIOException1);
    }
  }

  // ERROR //
  public Bitmap decode(InputStream paramInputStream, BitmapPool paramBitmapPool, int paramInt1, int paramInt2, DecodeFormat paramDecodeFormat)
  {
    // Byte code:
    //   0: invokestatic 295	com/bumptech/glide/util/ByteArrayPool:get	()Lcom/bumptech/glide/util/ByteArrayPool;
    //   3: astore 6
    //   5: aload 6
    //   7: invokevirtual 299	com/bumptech/glide/util/ByteArrayPool:getBytes	()[B
    //   10: astore 7
    //   12: aload 6
    //   14: invokevirtual 299	com/bumptech/glide/util/ByteArrayPool:getBytes	()[B
    //   17: astore 8
    //   19: invokestatic 301	com/bumptech/glide/load/resource/bitmap/Downsampler:getDefaultOptions	()Landroid/graphics/BitmapFactory$Options;
    //   22: astore 9
    //   24: new 98	com/bumptech/glide/load/resource/bitmap/RecyclableBufferedInputStream
    //   27: dup
    //   28: aload_1
    //   29: aload 8
    //   31: invokespecial 304	com/bumptech/glide/load/resource/bitmap/RecyclableBufferedInputStream:<init>	(Ljava/io/InputStream;[B)V
    //   34: astore 10
    //   36: aload 10
    //   38: invokestatic 310	com/bumptech/glide/util/ExceptionCatchingInputStream:obtain	(Ljava/io/InputStream;)Lcom/bumptech/glide/util/ExceptionCatchingInputStream;
    //   41: astore 11
    //   43: new 84	com/bumptech/glide/util/MarkEnforcingInputStream
    //   46: dup
    //   47: aload 11
    //   49: invokespecial 311	com/bumptech/glide/util/MarkEnforcingInputStream:<init>	(Ljava/io/InputStream;)V
    //   52: astore 12
    //   54: aload 11
    //   56: ldc 13
    //   58: invokevirtual 312	com/bumptech/glide/util/ExceptionCatchingInputStream:mark	(I)V
    //   61: new 191	com/bumptech/glide/load/resource/bitmap/ImageHeaderParser
    //   64: dup
    //   65: aload 11
    //   67: invokespecial 194	com/bumptech/glide/load/resource/bitmap/ImageHeaderParser:<init>	(Ljava/io/InputStream;)V
    //   70: invokevirtual 316	com/bumptech/glide/load/resource/bitmap/ImageHeaderParser:getOrientation	()I
    //   73: istore 33
    //   75: iload 33
    //   77: istore 22
    //   79: aload 11
    //   81: invokevirtual 317	com/bumptech/glide/util/ExceptionCatchingInputStream:reset	()V
    //   84: aload 9
    //   86: aload 7
    //   88: putfield 254	android/graphics/BitmapFactory$Options:inTempStorage	[B
    //   91: aload_0
    //   92: aload 12
    //   94: aload 10
    //   96: aload 9
    //   98: invokevirtual 321	com/bumptech/glide/load/resource/bitmap/Downsampler:getDimensions	(Lcom/bumptech/glide/util/MarkEnforcingInputStream;Lcom/bumptech/glide/load/resource/bitmap/RecyclableBufferedInputStream;Landroid/graphics/BitmapFactory$Options;)[I
    //   101: astore 24
    //   103: aload 24
    //   105: iconst_0
    //   106: iaload
    //   107: istore 25
    //   109: aload 24
    //   111: iconst_1
    //   112: iaload
    //   113: istore 26
    //   115: aload_0
    //   116: aload 12
    //   118: aload 10
    //   120: aload 9
    //   122: aload_2
    //   123: iload 25
    //   125: iload 26
    //   127: aload_0
    //   128: iload 22
    //   130: invokestatic 326	com/bumptech/glide/load/resource/bitmap/TransformationUtils:getExifOrientationDegrees	(I)I
    //   133: iload 25
    //   135: iload 26
    //   137: iload_3
    //   138: iload 4
    //   140: invokespecial 328	com/bumptech/glide/load/resource/bitmap/Downsampler:getRoundedSampleSize	(IIIII)I
    //   143: aload 5
    //   145: invokespecial 330	com/bumptech/glide/load/resource/bitmap/Downsampler:downsampleWithSize	(Lcom/bumptech/glide/util/MarkEnforcingInputStream;Lcom/bumptech/glide/load/resource/bitmap/RecyclableBufferedInputStream;Landroid/graphics/BitmapFactory$Options;Lcom/bumptech/glide/load/engine/bitmap_recycle/BitmapPool;IIILcom/bumptech/glide/load/DecodeFormat;)Landroid/graphics/Bitmap;
    //   148: astore 27
    //   150: aload 11
    //   152: invokevirtual 334	com/bumptech/glide/util/ExceptionCatchingInputStream:getException	()Ljava/io/IOException;
    //   155: astore 28
    //   157: aload 28
    //   159: ifnull +169 -> 328
    //   162: new 336	java/lang/RuntimeException
    //   165: dup
    //   166: aload 28
    //   168: invokespecial 339	java/lang/RuntimeException:<init>	(Ljava/lang/Throwable;)V
    //   171: athrow
    //   172: astore 13
    //   174: aload 6
    //   176: aload 7
    //   178: invokevirtual 343	com/bumptech/glide/util/ByteArrayPool:releaseBytes	([B)Z
    //   181: pop
    //   182: aload 6
    //   184: aload 8
    //   186: invokevirtual 343	com/bumptech/glide/util/ByteArrayPool:releaseBytes	([B)Z
    //   189: pop
    //   190: aload 11
    //   192: invokevirtual 346	com/bumptech/glide/util/ExceptionCatchingInputStream:release	()V
    //   195: aload 9
    //   197: invokestatic 348	com/bumptech/glide/load/resource/bitmap/Downsampler:releaseOptions	(Landroid/graphics/BitmapFactory$Options;)V
    //   200: aload 13
    //   202: athrow
    //   203: astore 34
    //   205: ldc 21
    //   207: iconst_5
    //   208: invokestatic 107	android/util/Log:isLoggable	(Ljava/lang/String;I)Z
    //   211: ifeq -127 -> 84
    //   214: ldc 21
    //   216: ldc 201
    //   218: aload 34
    //   220: invokestatic 204	android/util/Log:w	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
    //   223: pop
    //   224: goto -140 -> 84
    //   227: astore 19
    //   229: ldc 21
    //   231: iconst_5
    //   232: invokestatic 107	android/util/Log:isLoggable	(Ljava/lang/String;I)Z
    //   235: ifeq +14 -> 249
    //   238: ldc 21
    //   240: ldc_w 350
    //   243: aload 19
    //   245: invokestatic 204	android/util/Log:w	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
    //   248: pop
    //   249: aload 11
    //   251: invokevirtual 317	com/bumptech/glide/util/ExceptionCatchingInputStream:reset	()V
    //   254: iconst_0
    //   255: istore 22
    //   257: goto -173 -> 84
    //   260: astore 20
    //   262: ldc 21
    //   264: iconst_5
    //   265: invokestatic 107	android/util/Log:isLoggable	(Ljava/lang/String;I)Z
    //   268: istore 21
    //   270: iconst_0
    //   271: istore 22
    //   273: iload 21
    //   275: ifeq -191 -> 84
    //   278: ldc 21
    //   280: ldc 201
    //   282: aload 20
    //   284: invokestatic 204	android/util/Log:w	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
    //   287: pop
    //   288: iconst_0
    //   289: istore 22
    //   291: goto -207 -> 84
    //   294: astore 16
    //   296: aload 11
    //   298: invokevirtual 317	com/bumptech/glide/util/ExceptionCatchingInputStream:reset	()V
    //   301: aload 16
    //   303: athrow
    //   304: astore 17
    //   306: ldc 21
    //   308: iconst_5
    //   309: invokestatic 107	android/util/Log:isLoggable	(Ljava/lang/String;I)Z
    //   312: ifeq -11 -> 301
    //   315: ldc 21
    //   317: ldc 201
    //   319: aload 17
    //   321: invokestatic 204	android/util/Log:w	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I
    //   324: pop
    //   325: goto -24 -> 301
    //   328: aconst_null
    //   329: astore 29
    //   331: aload 27
    //   333: ifnull +39 -> 372
    //   336: aload 27
    //   338: aload_2
    //   339: iload 22
    //   341: invokestatic 354	com/bumptech/glide/load/resource/bitmap/TransformationUtils:rotateImageExif	(Landroid/graphics/Bitmap;Lcom/bumptech/glide/load/engine/bitmap_recycle/BitmapPool;I)Landroid/graphics/Bitmap;
    //   344: astore 29
    //   346: aload 27
    //   348: aload 29
    //   350: invokevirtual 357	java/lang/Object:equals	(Ljava/lang/Object;)Z
    //   353: ifne +19 -> 372
    //   356: aload_2
    //   357: aload 27
    //   359: invokeinterface 361 2 0
    //   364: ifne +8 -> 372
    //   367: aload 27
    //   369: invokevirtual 366	android/graphics/Bitmap:recycle	()V
    //   372: aload 6
    //   374: aload 7
    //   376: invokevirtual 343	com/bumptech/glide/util/ByteArrayPool:releaseBytes	([B)Z
    //   379: pop
    //   380: aload 6
    //   382: aload 8
    //   384: invokevirtual 343	com/bumptech/glide/util/ByteArrayPool:releaseBytes	([B)Z
    //   387: pop
    //   388: aload 11
    //   390: invokevirtual 346	com/bumptech/glide/util/ExceptionCatchingInputStream:release	()V
    //   393: aload 9
    //   395: invokestatic 348	com/bumptech/glide/load/resource/bitmap/Downsampler:releaseOptions	(Landroid/graphics/BitmapFactory$Options;)V
    //   398: aload 29
    //   400: areturn
    //
    // Exception table:
    //   from	to	target	type
    //   54	61	172	finally
    //   79	84	172	finally
    //   84	157	172	finally
    //   162	172	172	finally
    //   205	224	172	finally
    //   249	254	172	finally
    //   262	270	172	finally
    //   278	288	172	finally
    //   296	301	172	finally
    //   301	304	172	finally
    //   306	325	172	finally
    //   336	372	172	finally
    //   79	84	203	java/io/IOException
    //   61	75	227	java/io/IOException
    //   249	254	260	java/io/IOException
    //   61	75	294	finally
    //   229	249	294	finally
    //   296	301	304	java/io/IOException
  }

  public int[] getDimensions(MarkEnforcingInputStream paramMarkEnforcingInputStream, RecyclableBufferedInputStream paramRecyclableBufferedInputStream, BitmapFactory.Options paramOptions)
  {
    paramOptions.inJustDecodeBounds = true;
    decodeStream(paramMarkEnforcingInputStream, paramRecyclableBufferedInputStream, paramOptions);
    paramOptions.inJustDecodeBounds = false;
    int[] arrayOfInt = new int[2];
    arrayOfInt[0] = paramOptions.outWidth;
    arrayOfInt[1] = paramOptions.outHeight;
    return arrayOfInt;
  }

  protected abstract int getSampleSize(int paramInt1, int paramInt2, int paramInt3, int paramInt4);
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.bumptech.glide.load.resource.bitmap.Downsampler
 * JD-Core Version:    0.6.2
 */